package main;
import java.util.ArrayList;

public class MyCalendar extends Subject {
	private ArrayList<Event> cal;
	private int maxsize = 2;

	public MyCalendar(Observer o, String cn) {
		super(cn);
		minsize = 1;
		cal = new ArrayList<>();
		attach(o);
	}

	public String getName() {return name;}
	public ArrayList<Event> getEvents() {return cal;}

	public void addEvent(Event e) {
		cal.add(e);
		notifyAddedEvents(e);
	}

	public void removeEvent(Event e) {
		cal.remove(e);
		notifyRemovedEvents(e);
	}

	@Override
	public void attach(Observer o) {
		if (observers.size() == maxsize)
			throw new MaximalSizeException();
		else {
			super.attach(o);
			o.updateAll(cal);
		}
	}
}
